package ilender.controller;

import lombok.*;

import com.google.gson.*;

import ilender.annotations.*;
import ilender.dispatching.ControllerTools;
import ilender.mappers.*;
import ilender.models.*;
import ilender.util.*;
import ilender.facebook.*;

/**
 * @see Controller
 */
@Controller("categories")
public class CategoriesController{
	/**
	 * Generate autocomplete list for categories.
	 *
	 * @param request <pre>
	 * {
	 *     term:(the search string)
	 * }
	 * </pre>
	 * @return <pre>
	 * [
	 *     {
	 *         label:(category name),
	 *         value:(category id)
	 *     },
	 *     ...
	 * ]
	 * </pre>
	 */
	public static JsonElement autocomplete(JsonObject request,ControllerTools tools){
		return JsonTools.makeAutocompleteEntriesArray(
				tools.session.getMapper(CategoriesMapper.class).searchCategories(request.get("term").getAsString()),
				"name");
	}
}
